package com.qyer.lxp.service.errorlog.impl;

import com.qyer.lxp.common.framework.core.BaseSpringService;
import com.qyer.lxp.dao.errorlog.TaskErrorLogMapper;
import com.qyer.lxp.model.errorlog.TaskErrorLog;
import com.qyer.lxp.service.errorlog.ITaskErrorLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 错误日志服务实现类
 * Created by jiangping on 16/6/2.
 */
@Service
public class TaskErrorLogServiceImpl extends BaseSpringService implements ITaskErrorLogService{

    @Resource
    private TaskErrorLogMapper taskErrorLogMapper;

    /**
     * 插入错误日志
     *
     * @param taskErrorLog 错误信息
     * @throws Exception
     */
    @Override
    public void insertTaskErrorLog(TaskErrorLog taskErrorLog) {
        try {
            taskErrorLogMapper.insertTaskErrorLog(taskErrorLog);
        } catch (Exception e) {
            logger.error("调用错误日志接口异常",e);
        }
    }

    /**
     * 查询错误日志,默认每次查50条
     *
     * @return 返回日志结果
     * @param  taskErrorLog 请求参数
     * @throws Exception
     */
    @Override
    public List<TaskErrorLog> setlectTaskErrorLog(TaskErrorLog taskErrorLog) {
        try {
            return taskErrorLogMapper.setlectTaskErrorLog(taskErrorLog);
        } catch (Exception e) {
            logger.error("调用错误日志接口异常",e);
        }
        return null;
    }

    /**
     * 查询错误日志表数据总数
     *
     * @return 返回总记录数
     */
    @Override
    public int countTaskErrorLog(TaskErrorLog taskErrorLog) {
        try {
            return taskErrorLogMapper.countTaskErrorLog(taskErrorLog);
        } catch (Exception e) {
            logger.error("调用错误日志接口异常",e);
        }
        return 0;
    }

    /**
     * 批量删除错误日志
     *
     * @param ids 主键id集合
     * @return 返回删除结果
     * @throws Exception
     */
    @Override
    public int deleteBacthByPrimaryKey(List<Integer> ids) {
        try {
            return taskErrorLogMapper.deleteBacthByPrimaryKey(ids);
        } catch (Exception e) {
            logger.error("调用错误日志接口异常",e);
        }
        return 0;
    }

    /**
     * 删除某条错误日志
     *
     * @param id 主键id
     * @return 返回删除结果
     * @throws Exception
     */
    @Override
    public int deleteTaskErrorLogByPrimaryKey(int id) {
        try {
            return taskErrorLogMapper.deleteTaskErrorLogByPrimaryKey(id);
        } catch (Exception e) {
            logger.error("调用错误日志接口异常",e);
        }
        return 0;
    }

    /**
     * 批量插入异常的产品code
     *
     * @param params 产品code集合
     * @throws Exception
     */
    @Override
    public void insertBatchTaskErrorLog(List<TaskErrorLog> params) {
        try {
            taskErrorLogMapper.insertBatchTaskErrorLog(params);
        } catch (Exception e) {
            logger.error("调用错误日志接口异常",e);
        }
    }

    /**
     * param集合
     *
     * @return
     * @throws Exception
     */
    @Override
    public List<String> setlectTaskErrorLogForParam() {
        try {
            return taskErrorLogMapper.setlectTaskErrorLogForParam();
        } catch (Exception e) {
            logger.error("调用错误日志接口异常",e);
        }
        return null;
    }
}
